package org.luxor.eshop.account.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

/**
 * TCC 收款
 *
 * @author Mr.Yan  @date: 2020/12/8
 */
@LocalTCC
public interface ReceiptTccAction {

    /**
     * 第一阶段：预留资源(Prepare)
     *
     * @param actionContext  上下文对象，用来在两个阶段之间传递数据
     * @param billCode       账单编号
     * @param receiptAccount 收款账户
     * @param amounts        收款金额
     * @return 预留业务资源成功? (true-成功; false-失败)
     */
    @TwoPhaseBusinessAction(name = "receiptTccAction", commitMethod = "commit", rollbackMethod = "rollback")
    boolean prepare(BusinessActionContext actionContext,
                    @BusinessActionContextParameter(paramName = "billCode") Long billCode,
                    @BusinessActionContextParameter(paramName = "receiptAccount") String receiptAccount,
                    @BusinessActionContextParameter(paramName = "amounts") BigDecimal amounts);

    /**
     * 第二阶段：确认/提交(Commit)
     *
     * @param actionContext 上下文对象，用来在两个阶段之间传递数据
     * @return 确认成功？(true-成功; false-失败)
     */
    boolean commit(BusinessActionContext actionContext);

    /**
     * 第二阶段：取消/回滚(Rollback)
     *
     * @param actionContext 上下文对象，用来在两个阶段之间传递数据
     * @return 取消成功？(true-成功; false-失败)
     */
    boolean rollback(BusinessActionContext actionContext);
}
